<%@ page language="java" contentType="text/html; charset=utf-8 " import="java.util.Date,java.text.*,domain.User,java.util.ArrayList,domain.Community,dao.community.*,java.util.List"
    pageEncoding="utf-8"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="<%=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/" %>"/>
    <meta charset="utf-8" />
	title>用户管理</title>
</head>

<script type="text/javascript">
	function messageLoad(){
		var message = '<%=request.getAttribute("message") %>';
		if(message != 'null'){
			alert(message);
		}
	}
	var xmlHttp;
	function createXMLHttp(){
		if(window.XMLHttpRequest){
			xmlHttp=new XMLHttpRequest();
		}
		else{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	function checkUsername(){
		var username1=document.getElementById("newUsername").value;
		createXMLHttp();
		xmlHttp.onreadystatechange=checkUsernameCallback;
		xmlHttp.open("post","adminValidateName?newUsername="+username1);
		xmlHttp.send(null);
		document.getElementById("info").innerHTML="正在验证`````";
	}
	function checkUsernameCallback(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.status==200){
				if(xmlHttp.responseText!=""&&xmlHttp.responseText!=null){
					document.getElementById("info").innerHTML="<font color='red'>用户名已经存在</font>";
					document.getElementById("submit").disabled=true;
				}
				else{
					 document.getElementById("info").innerHTML="<font color='green'>可以使用</font>";
					 document.getElementById("submit").disabled=false;
				}
			}
		}
	}
	function beforeSubmit(){
		if(document.getElementById('newUsername').value==''){
			alert('用户名不能为空！');
			document.getElementById('newPassword').focus();
			return false;
		}
		if(document.getElementById('newPassword').value==''){
			alert('密码不能为空！');
			document.getElementById('newPassword').focus();
			return false;
		}
	}
	function beforeSubmit1(){
		if(document.getElementById('updatePassword').value==''){
			alert('修改后的密码不能为空！');
			document.getElementById('updatePassword').focus();
			return false;
		}
	}
</script>

    	<style type="text/css">
    		body{
    		color: #555;
    		background-color: rgba(0, 0, 0, 0.08);
    		font-size: 80%;
    			}
    		.navigation{
    			position: absolute;
    			height: 100%;
    			width: 20%;
    			top: 0;
    			left: 0;
    			box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
    			background: white;
    		}
    		.top{
    			position: absolute;
    			top: 0;
    			left: 21%;
    			height: 10%;
    			width: 78%;
    			box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
    			background: white;
    		}
    		.main{
    			position: absolute;
    			top: 12%;
    			left: 21%;
    			width: 78%;
    			height: 86%;
    			box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
    			background: white;
    		}
    		.logo{
    			margin: auto;
    			margin-top: 10%;
    			background: url(img/logo.png);
    			width: 60%;
    			margin-bottom:10% ;
    		}
    		.click_box{
    			text-align: center;
    			border-top: black solid 1px;
    			border-bottom: black solid 1px ;
    			background: #199ED8;
    			color: white;
    			padding: 3%;
    			font-size: 160%;
    		}
    		.unclick_box{
    			text-align: center;
    			border-top: black solid 1px;
    			border-bottom: black solid 1px ;
    			padding: 3%;
    			font-size: 160%;
    		}
    		.unclick_box:hover{
    			background: #199ED8;
    			color: white;
    		}
    		.out_login:hover{
    			color: #199ED8;
    		}
    		button{
            			margin:10px;
            			background: #199ED8;
            			font-size: 100%;
            			color: white;
            			width: 100px;
            			height: 30px;
            			border: 0px;
            			border-radius: 5px;
            		}

            		table{
            			position: relative;
            			top: 0;

            			min-height: 25px;
            			line-height: 25px;
            			text-align: center;
            			border-collapse: collapse;
            			top: 0%;
            			left: 5%;
            			width: 90%;
            			height: 75%;

            		}
            		td{
            			height: 6%;

            		}
            		th{
            			background: #199ED8;
            			color: white;
            		}
            		table tr:nth-child(odd){
            			background: #F2F2F2;
            		}
            		#shadow{
                    				background: #000;
                    				filter: alpha(opacity=50); /* IE的透明度 */
                    				opacity: 0.9; /* 透明度 */
                    				display: none;
                    				position: fixed;
                    				top: 0px;
                    				left: 0px;
                    				width: 100%;
                    				height: 100%;
                    				z-index: 100; /* 此处的图层要大于页面 */
                    				display: none;
                    			}
                    			.box{
                    				border: 1px solid black;
                    				width: 30%;
                    				height: 40%;
                    				position: fixed;
                    				top: 30%;
                    				left: 35%;
                    				opacity: 1;
                    				margin: 0 auto;
                    				text-align: center;
                    				background: white;
                    				border-radius: 5px;
                    				z-index: 101;
                    				box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
                    			}
                    			.title{
                    				width: 100%;
                    				background: #F2F2F2;
                    				height: 15%;
                    				border-top-left-radius: 5px;
                    				border-top-right-radius: 5px;
                    				box-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px 0px;
                    				border-bottom: 0.5px antiquewhite solid;
                    			}
                input{
			                border: 1px solid #ccc;
			                padding: 7px 0px;
			                border-radius: 3px;
			                padding-left:5px;
			                -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
			                box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
			                -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
			                -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
			                transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s
			            }
			            input:focus{
			                    border-color: #66afe9;
			                    outline: 0;
			                    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
			                    box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)
			            }
                        .choose {
						                position: relative;
						            }
						            .input_check {
						                position: absolute;
						                visibility: hidden;

						            }
						            .input_check+label {
						                display: inline-block;
						    padding: 2px;
						                border: 1px solid black;
						                cursor: pointer;
						    border-radius: 5px;
							   box-shadow: rgba(0, 0, 0, 0.08) 0px 3px 4px 0px;
						            }
						            .input_check:checked+label:after {
						                content: "";
						                position: absolute;
						                left: 2px;
						                bottom: 12px;
						                width: 9px;
						                height: 4px;
						                border: 2px solid #199ED8;
						                border-top-color: transparent;
						                border-right-color: transparent;
						                -ms-transform: rotate(-60deg);
						                -moz-transform: rotate(-60deg);
						                -webkit-transform: rotate(-60deg);
						                transform: rotate(-45deg);
						            }
    	</style>
    	<%
                    	User user=new User();
                    	if(session.getAttribute("adminloginflag")==null){
                    	%>
                    	<script type="text/javascript">
                    	    window.location.href="admin/login.jsp";
                    	</script>
                        <% }else{
                        user=(User)session.getAttribute("adminloginflag");
                        %>
    	<body onload="messageLoad()">
    		<div class="navigation">
    			<center><img src="image/logo.png" class="logo"  /></center>
    			<% if(user.getUsername().equals("admin")){ %><div class="click_box" onclick="userManage()">用户配置</div> <% } %>
    			<% if(user.getCommunity_power()==1 ){%><div class="unclick_box" onclick="Community()">社区配置</div> <% } %>
    			<% if(user.getRoom_power()==1 ){%><div class="unclick_box" onclick="Room()">住房审核</div> <% } %>
    			<% if(user.getView_power()!=null&&!user.getView_power().equals("null") ){%><div class="unclick_box" onclick="info()">人员信息</div> <% } %>
    		</div>
    		<div class="top">
    			<div style="float: left;margin:2%;font-size: 160%;"><%=new SimpleDateFormat("yyyy-MM-dd E").format(new Date())  %></div>
    			<div style="float: right;margin:2%;font-size: 160%;">
    				<span> <img src="image/u954.svg"/></span>
    				<span style="margin-right: 20px;"><%=user.getUsername() %></span>
    				<span class="out_login" onclick="AdminOutlogin()">退出</span>
    			</div>
    		</div>
    		<div class="main">
                <div style="float: right;margin-right: 5%;margin-top: 3%;"><button onclick="showCreatUser()">创建新用户</button></div>
					<table border="1">
						<tr>
						<th width="25%">用户名</th>
						<th width="30%">查看权限</th>
						<th width="10%">审核权限</th>
						<th width="10%">社区权限</th>
						<th width="10%">住房权限</th>
						<th width="15%">操作</th>
						</tr>
						<% for(int i=0;i<15;i++){ %>
						<tr>
						<% ArrayList<User> list=new ArrayList<User>();
						list=(ArrayList)request.getAttribute("list");
						   if(i<list.size()){
						   String viewPowerName =null;
						%>
						<td><%=list.get(i).getUsername() %></td>
						<td><%if(list.get(i).getView_power()==null||list.get(i).getView_power()==""||list.get(i).getView_power().equals("null")){ %>无<%}else{
						CommunityDao cD =new CommunityDaoImpl() ;
						viewPowerName = cD.getIdForName(list.get(i).getView_power()); %><p style="margin:auto;text-align:center;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;width:200px;" title="<%=viewPowerName %>"><%=viewPowerName %></p><% } %>
						</td>
						<% if(list.get(i).getVerify_power()==1){ %><td style="color:green;">√</td><%}else{ %><td style="color:red">× </td><% } %>
						<% if(list.get(i).getCommunity_power()==1){ %><td style="color:green;">√</td><%}else{ %><td style="color:red">× </td><% } %>
						<% if(list.get(i).getRoom_power()==1){ %><td style="color:green;">√</td><%}else{ %><td style="color:red">× </td><% } %>
						<td><a onclick="show1(<%=list.get(i).getUser_id() %>,'<%=list.get(i).getUsername() %>')">修改</a>&nbsp;&nbsp;&nbsp;<a onclick="showPower(<%=list.get(i).getUser_id() %>)">权限配置</a></td>
						</tr><%} else{%>
						<td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><%}}%>
					</table>
					<div style="float: right;margin-right: 5%;margin-top: 1%;">
					<c:choose>
								<c:when test="${page.hasPrePage}">
									<a href="UserInfo?method=list&currentPage=1">首页</a> |
							<a href="UserInfo?method=list&currentPage=${page.currentPage -1 }">上一页</a>
								</c:when>
								<c:otherwise>

								</c:otherwise>
							</c:choose>
						   当前为第${page.currentPage}页,共${page.totalPage}页
							<c:choose>
								<c:when test="${page.hasNextPage}">
									<a href="UserInfo?method=list&currentPage=${page.currentPage + 1 }">下一页</a> |
							<a href="UserInfo?method=list&currentPage=${page.totalPage }">尾页</a>
								</c:when>
								<c:otherwise>

								</c:otherwise>
							</c:choose>
				</div>

    		</div>
    		<div id="shadow">
				<div class="box" id="creatuserbox">
					<div class="title">
						<span style="margin:5px;float: left;font-weight: 600;">创建新用户</span><span style="float: right;margin: 10px;font-weight: 800;" onclick="hidden2()">X</span>
					</div><br /><br />
					<form action="adminCreatUser" method="post" onsubmit="return beforeSubmit(this)">
						<input type="text" id="newUsername" name="newUsername" placeholder="账号" onblur="checkUsername()"/> <br />
						<span id="info"></span><br /><br />
						<input type="password" id="newPassword" name="newPassword" placeholder="密码"/><br /><br />
						<button id="submit" type="submit">确认创建</button>
					</form>
				</div>

				<div class="box" id="updateUser">
					<div class="title">
						<span style="margin:5px;float: left;font-weight: 600;">修改用户信息</span><span style="float: right;margin: 10px;font-weight: 800;" onclick="hidden2()">X</span>
					</div><br /><br />
					<form id="updateUserform" method="post" onsubmit="return beforeSubmit1(this)">
					<div style="width:60%;text-align: left;margin: auto;"><span id="fontUser"></span><br /><br />
						<input type="password" id="updatePassword" name="updatePassword" placeholder="修改密码"/><br /><br />
						<button type="submit" >确认修改</button>
						</div></form>
					</div>
					<div class="box" id="showPower" style="text-align:left;padding:10px;height:50%;top:20%">
						<div class="title">
						<span style="margin:5px;float: left;font-weight: 600;">权限配置</span><span style="float: right;margin: 10px;font-weight: 800;" onclick="hidden2()">X</span>
					</div><br />
					<h3 align="left">查看权限</h3>
					<form method="post" id="Powerform">
					<%  CommunityDao communityDao =new CommunityDaoImpl() ;
						List<Community> li = communityDao.getCommunityList();
						int x=1;
						for(int j=0;j<li.size();j++,x++){
					%>
					<span class="choose"><input type="checkbox" class="input_check" name="viewPower" id="check<%=j %>" value="<%=li.get(j).getCommunity_id() %>" ><label for="check<%=j %>"><%=li.get(j).getCommunity_name() %></label></span>
					<% if(x%4==0){ %><br /> <% }} %>
					<br /><br />
					<span style="font-weight: 900;">审核权限：</span><span><input type="radio" value="1" name="shPower" id="shPower" />是</span><span><input type="radio" value="0" name="shPower" id="shPower"/>否</span><br />
					<span style="font-weight: 900;">社区权限：</span><span><input type="radio" value="1" name="cPower" id="cPower" />是</span><span><input type="radio" value="0" name="cPower" id="cPower"/>否</span><br />
					<span style="font-weight: 900;">住房权限：</span><span><input type="radio" value="1" name="rPower" id="rPower" />是</span><span><input type="radio" value="0" name="rPower" id="rPower"/>否</span><br /><br />
					<center><button type="submit" >配置权限</button></center></form>
					</div>
			</div>
    	</body>
    	<% } %>
    	<script type="text/javascript">
        	    function AdminOutlogin(){
        	    	window.location.href="AdminOutLogin";
        	    }
        	    function userManage(){
                    window.location.href="UserInfo";
                }
                function Community(){
                    window.location.href="CommunityInfo";
                 }
                function Room(){
                    window.location.href="RoomInfo";
                 }
                function info(){
                    window.location.href="Info";
                 }
                function hidden2(){
					document.getElementById("shadow").style.display="none";
					document.getElementById("updateUser").style.display="none";
					document.getElementById("creatuserbox").style.display="none";
					document.getElementById("showPower").style.display="none";

				}
				function showCreatUser(){
					document.getElementById("shadow").style.display="block";
					document.getElementById("creatuserbox").style.display="block";
					document.getElementById("updateUser").style.display="none";
					document.getElementById("showPower").style.display="none";
				}
			    function show1(e,n){
					document.getElementById("shadow").style.display="block";
					document.getElementById("updateUser").style.display="block";
					document.getElementById("updateUserform").action="AdminupdatUser?User_id="+e;
					document.getElementById("fontUser").innerHTML="用户名："+n;
					document.getElementById("creatuserbox").style.display="none";
					document.getElementById("showPower").style.display="none";
				}

				 function showPower(e){
					document.getElementById("shadow").style.display="block";
					document.getElementById("showPower").style.display="block";
					document.getElementById("Powerform").action="AdminPower?User_id="+e;
					document.getElementById("creatuserbox").style.display="none";
					document.getElementById("updateUser").style.display="none";
				}
        	</script>
    </html>
